home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / gnu / objcissu.lha / class-Class < prev    next >
Text File  |  1993-02-27  |  11KB  |  286 lines

  1. Return-Path: <krab@iesd.auc.dk>
  2. Date: Wed, 24 Feb 1993 19:33:38 +0100
  3. From: Kresten Krab Thorup <krab@iesd.auc.dk>
  4. To: gnu-objc@gnu.ai.mit.edu
  5. Subject: Introducing class Class
  6. Cc: krab@iesd.auc.dk, rms@gnu.ai.mit.edu, burchard@geom.umn.edu
  7.  
  8. Hi again...
  9.  
  10. I am considering the possibility to introduce a class Class in
  11. objective C -- i.e. the class of class Objects, somewhat like it is
  12. known in Smalltalk.
  13.  
  14. The benefits we would get from this was that all the `highlevel'
  15. functionality of the runtime could actually be coded in objective C --
  16. that is, most of the `objc_<doSomething>()' functions could be
  17. avoided.  In my opinion these are ugly!  For instance, I would prefer:
  18.  
  19.     [<SomeClass> setVersion: XX];
  20. over
  21.     objc_setVersion(<SomeClass>, XX);
  22.  
  23. Besides, this would make it considerably simpler to understand the
  24. entire concept of classes and metaclasses as objects existing at
  25. runtime. 
  26.  
  27. I suppose you're confused -- objc does not allow for descriptions of
  28. classes like that!  The classes and metaclasses are generated by the
  29. compiler!  What do you mean!?
  30.  
  31. The trick is to introduce the class Class, as a subclass of `Object'.
  32. Then as the runtime is being initialized, install the `class object
  33. for class Class' as the `superclass for the metaclass of class Object.'
  34. The class hierachy then comes out as the illustration below.. It is
  35. the `snaky' link which is additionally installed by the runtime.
  36. Aditionally, the `isa' link for `meta Object' should point to `meta
  37. Class'.   
  38.  
  39.                         ,=======.                                 
  40.                        ||       \/                                
  41.            [Object]----||-->[meta Object]--.                            
  42.               ||       ||        ||        |                             
  43.               ||       ||        ||        |                             
  44.               \/       ||        \/        |                             
  45.             [Class]----||--->[meta Class]<-'
  46.               ||       ||
  47.                `======='                                          
  48.                              Ledgend:  A ==> B     B inherits A
  49.                                        A --> B     A is instance of B
  50.  
  51.  
  52. This allows for the most basic factory methods now in class Object to
  53. be implemented as instance methods in class Class.  But!  In order to
  54. conform to the objective C `standard' (did I say standard?) class
  55. Object must implement the factory methods `currently' implemented there
  56. -- no problem, we will simply make them `subclassResponsibility's and
  57. really implement them in class Class.
  58.  
  59. Indeed this opens the possibility that part of the runtime is coded in
  60. objective C, but the introduction of class Class does not nessecarily
  61. cost anything for the runtime, since we could still just implement the
  62. entire thing in C.  However, the factory methods of class Object which
  63. already implement some kind of runtime interface could be placed in
  64. class Class at no additional cost.
  65.  
  66. The following is the interface for this new class Class.  The methods
  67. from class Object which are related to class manipulation are put in a
  68. special category (Class) along with class Class.  In order to make the
  69. thing consistent, I renamed `name' to `className', and class Class now
  70. implements `name' in the strightforward meaning, and also `super'
  71. which just returns the super link.  
  72.  
  73. /Kresten
  74.  
  75. /*
  76.  * The runtime installs this the class object for this class as the
  77.  * superclass for the metaclass of class Object.  
  78.  *
  79.  * Instances of this class (or rather its subclasses) are generated by
  80.  * the compiler for each class in the system.  Hence, the number, type
  81.  * and order of instance variables should *not* be changed unless gcc
  82.  * is updated accordingly!
  83.  *
  84.  */
  85.  
  86. @interface Class : Object
  87. {
  88.   Class*          super_class;
  89.   const char*            name;
  90.   long             version;
  91.   long             info;
  92.   long             instance_size;
  93.   IvarList*         ivars;
  94.   MethodList*        methods;
  95.   DispatchTable*        dtable;
  96. }
  97.  
  98. + (BOOL)isClass;        /* allways answers NO */
  99. - (BOOL)isClass;        /* allways answers YES */
  100.  
  101. + (BOOL)isMetaClass;        /* allways answers YES */
  102. - (BOOL)isMetaClass;        /* allways answers NO */
  103.  
  104. - new;                /* answer a new object */
  105. + new;                /* shouldNotImplement */
  106.  
  107. - alloc;            /* allocate an object */
  108. + alloc;            /* shouldNotImplement */
  109.  
  110. - free;                /* shouldNotImplement */
  111.  
  112. - (Class*)super;        /* answer super link (super_class) */
  113.  
  114. - (BOOL)instancesRespondsTo: (SEL)aSelector; /* do whatever... */
  115.  
  116. - poseAs: (Class*)aClassObject;    /* do whatever... */
  117.  
  118. - (int)version;            /* set and get version */
  119. - setVersion:(int)aVersion;
  120.  
  121. - (const char*) name;        /* the name of *this* class */
  122.  
  123. @end
  124.  
  125.  
  126. /* **************************************************************
  127.  * Add Class operations to class Object 
  128.  * ************************************************************** */
  129.  
  130. @interface Object (Class)
  131.  
  132. - (BOOL)isClass;        /* allways answers NO */
  133. - (BOOL)isMetaClass;        /* allways answers NO */
  134.  
  135. + new;                /* subclassResponsibility */
  136. + alloc;            /* subclassResponsibility */
  137.  
  138. - init;                /* user level initialize */
  139.  
  140. + free;                /* shouldNotImplement */
  141. - free;                /* actually free it */
  142.  
  143. - copy;                /* [self shallowCopy] */
  144. - shallowCopy;            /* (*_objc_copy)(self) */
  145. - deepCopy;            /* [[self shallowCopy] deep] */
  146. - deep;                /* just return self */
  147.  
  148. - (Class*)class;        /* isa */
  149. - (Class*)superClass;        /* [isa super] */
  150.  
  151. - (const char*)className;    /* [isa name] */
  152. - self;                /* self */
  153.  
  154. - (BOOL)isKindOf: (Class*)aClassObject;
  155. - (BOOL)isMemeberOf: (Class*)aClassObject;
  156. - (BOOL)isKindOfGivenName: (const char*)aClassName;
  157. - (BOOL)isMemberOfGivenName: (const char*)aClassName;
  158.  
  159. + (IMP)methodFor: (SEL)aSelector; /* subclassResponsibility */
  160. + (BOOL)instancesRespondsTo: (SEL)aSelector; /* subclassResponsibility */
  161. - (BOOL)respondsTo: (SEL)aSelector; /* [isa instancesRespondsTo: aSel] */
  162.  
  163. - perform: (SEL)aSelector;    /* (*[isa methodFor: aSelector])() */
  164. - perform: (SEL)aSelector with: anObject; /* ditto with arg */
  165.  
  166. + poseAs: (Class*)aClassObject;    /* subclassResponsibility */
  167.  
  168. + (long)version;        /* subclassResponsibility */
  169. + setVersion:(long)aVersion;    /* subclassResponsibility */
  170.  
  171. @end
  172.  
  173.  
  174.  
  175.  
  176. Return-Path: <Steve_Naroff@NeXT.COM>
  177. From: Steve_Naroff@NeXT.COM (Steve Naroff)
  178. Date: Wed, 24 Feb 93 11:19:44 -0800
  179. To: Kresten Krab Thorup <krab@iesd.auc.dk>
  180. Subject: Re: Introducing class Class
  181. Cc: gnu-objc@gnu.ai.mit.edu, krab@iesd.auc.dk, rms@gnu.ai.mit.edu,
  182.         burchard@geom.umn.edu
  183.  
  184.  
  185. I think this is really worthwhile (and a cleanup we have wanted to do  
  186. for sometime now). Our newer work is described in terms of the  
  187. language it implements (like protocols, which are described in  
  188. Objective-C, not C). 
  189.  
  190.  
  191. Protocols are "sealed" classes (ie. they can't be subclassed). I  
  192. imagine you intend for the class Class to be sealed. I haven't  
  193. flushed out about the implementation issues, but it would be nice to  
  194. add state and behavior to a Class object. Obviously, this is one way  
  195. to view class variables, as an extension of the Class object.
  196.  
  197. I hope to make time and give you more feedback on your proposal.
  198.  
  199. snaroff.
  200.  
  201. Date: Fri, 26 Feb 1993 01:13:46 +0100
  202. From: Kresten Krab Thorup <krab@iesd.auc.dk>
  203. To: rasmus@dannug.dk
  204. Cc: gnu-objc@prep.ai.mit.edu
  205. In-Reply-To: <9302251923.AA01265@peter.dannug.dk>
  206. Subject: Re: Class Variables
  207.  
  208. Peter Rasmussen (pra@iesd.auc.dk) writes: 
  209. >If class variables were to be introduced into the GNU Objective-C  
  210. >system object system, then things would be different. Then they would  
  211. >be inherited by subclasses and their definition would be relevant to
  212. >place into the @interface def. 
  213.  
  214. This would fit nicely into the idea of a class Class.  class Class
  215. will contain the `default' attributes of a class object as instance
  216. variables.  These are really class variables -- it does make sense to
  217. say MyClass->super_class, and hence the concept is already there.
  218. Now, additionally introduced class variables are simply appended to
  219. the layout of a class object, exactly as the case is for instances.
  220. The only fuss is to implement it, and agree on some syntax.
  221. Personally I like the `+' and optional `-' in front of variable
  222. declarations.
  223.  
  224. /Kresten
  225.  
  226. Date: Fri, 26 Feb 1993 01:48:00 +0100
  227. From: Kresten Krab Thorup <krab@iesd.auc.dk>
  228. To: Bruce Nilo <bruce@ictv.com>
  229. In-Reply-To: <199302252000.AA00891@taos.ictv.com>
  230. Subject: Re: Introducing class Class
  231. Cc: krab@iesd.auc.dk, gnu-objc@gnu.ai.mit.edu
  232.  
  233. Bruce Nilo writes:
  234. >Ideally different meta class objects could be introduced which would  
  235. >enable one to define different semantics to various aspects of the  
  236. >runtime. If at all possible it would be great if you did not have to  
  237. >seal the class Class.
  238.  
  239. In order to be able to subclass class Class meaningfully, I think
  240. there should be introduced completely new language mechanisms.  To me
  241. it is fine if such subclassing is the job of the compiler (i.e.
  242. metaclasses for ordinary classes would be subclasses of class Class)
  243.  
  244. >For example, I would love to be able to create a meta class whose  
  245. >runtime access to instance variables could be modified to support  
  246. >versioning and/or persistence. Or perhaps the default method dispatch  
  247. >could be overriden to provide some kind of rudimentary method  
  248. >combination as is required by an application or a family of  
  249. >applications.
  250.  
  251. For the matter of method dispatch it could be meaningfull, but this
  252. could simply be introduced by having a convention about a specific
  253. fatory method name [MyClass methodFor: sSelector] which is used in the
  254. dispatcher.   During normal usage, the dispatcher could be statically
  255. bound to that factory method (defined in class Class perhaps) but if
  256. it is redefined somewhere we could hadle this specially.
  257.  
  258. >Issues relating to default runtime performance versus refined runtime  
  259. >performance would have to be addressed. Does your idea support this  
  260. >notion of adapting the runtime programmatically? If so what aspects  
  261. >do you envision as being customizable? Would it be too hard to do  
  262. >this and have a fast default runtime? Does the idea sound at all  
  263. >appealing?
  264.  
  265. Ideally the messenger should be expanded inline, but perhaps with an
  266. escape to an alternative messenger... Somewhat like:
  267.  
  268.    inline IMP  
  269.    objc_msgSend (id receiver, SEL sel)
  270.    {
  271.      if(objc_altMsgSend)
  272.        return (*objc_altMsgSend)(receiver,sel);
  273.      if(!receiver)
  274.        receriver = nilObject;
  275.      return sarray_get(receiver->class_pointer->dtable, (unsigned)sel);
  276.    }  
  277.  
  278. As it is in my current experimental runtime.  This alternative
  279. messenger could then be an entrance to an Class based message lookup
  280. mechanism.  However, once we get forwarding up running anything is
  281. possible without the extra hack by installing magic handlers directly
  282. in the dispatch table.
  283.  
  284. /Kresten
  285.  
  286.